package com.lab303.powerproject.repository;

import com.lab303.powerproject.entity.PredictData;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;

public interface PredictDataRepository extends JpaRepository<PredictData,Integer> {

    @Query(nativeQuery = true,value = "select * from predict_data pd where date(pd.date) = curdate()")
    List<PredictData> findPredictDataByDeviceId();

    @Query(nativeQuery = true,value = "select * from predict_data pd order by pd.date desc limit 1")
    PredictData getPredictDataByDate();

    @Query(nativeQuery = true,value = "select * from predict_data pd where pd.predict_device_id = ?1 order by pd.date desc limit 1")
    PredictData getPredictDataByDateAndDEiveId(Integer deviceId);

    @Query(nativeQuery = true,value = "select * from predict_data pd where DATE_FORMAT(pd.date,'%Y-%m-%d')=?1 and pd.predict_device_id = ?2")
    PredictData findPredictDataByDateAndDayAnId(String day,Integer id);
}
